{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "96ac073d",
   "metadata": {},
   "source": [
    "## 第一题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "0245ff93",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "87442\n"
     ]
    }
   ],
   "source": [
    "from pandas import *\n",
    "fp = DataFrame(read_csv('gaze.csv'))\n",
    "data = fp[\"confidence\"]\n",
    "a = []\n",
    "for i in data:\n",
    "    if i > 0.9:\n",
    "        a.append(i)\n",
    "print(len(a))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b1e0c0a2",
   "metadata": {},
   "source": [
    "## 第二题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "13436bda",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99535\n"
     ]
    }
   ],
   "source": [
    "from pandas import *\n",
    "import math\n",
    "fp = DataFrame(read_csv('gaze.csv'))\n",
    "data_1 = fp[\"norm_pos_x\"]\n",
    "data_2 = fp[\"norm_pos_y\"]\n",
    "def s_d(data):\n",
    "    i = 0\n",
    "    lenth = len(data)\n",
    "    num = 0\n",
    "    num_1 = 0\n",
    "    for i in data:\n",
    "        num = num + i\n",
    "    average = num / lenth\n",
    "    for i in data:\n",
    "        num_1 += (i - average) ** 2\n",
    "    sd = (num_1/lenth) ** 1/2\n",
    "    l_sigma = average - 3*sd\n",
    "    r_sigma = average + 3*sd\n",
    "    return (l_sigma, r_sigma)\n",
    "\n",
    "tup_1 = s_d(data_1)\n",
    "tup_2 = s_d(data_2)\n",
    "\n",
    "number = 0\n",
    "for i in range(len(data_1)):\n",
    "    if (data_1[i] > tup_1[0] and data_1[i] < tup_1[1]) and (data_2[i] > tup_2[0] and data_2[i] < tup_2[1]):\n",
    "        number = number + 1\n",
    "print(number)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04919dcc",
   "metadata": {},
   "source": [
    "## 第三题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "78b38ba4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0         1970-01-02 08:29:10+776780\n",
      "1         1970-01-02 08:29:10+776790\n",
      "2         1970-01-02 08:29:10+779710\n",
      "3         1970-01-02 08:29:10+779760\n",
      "4         1970-01-02 08:29:10+787490\n",
      "                     ...            \n",
      "125259    1970-01-02 08:34:03+695600\n",
      "125260    1970-01-02 08:34:03+697570\n",
      "125261    1970-01-02 08:34:03+701580\n",
      "125262    1970-01-02 08:34:03+703610\n",
      "125263    1970-01-02 08:34:03+705570\n",
      "Name: gaze_timestamp, Length: 125264, dtype: object\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "from datetime import datetime\n",
    "import csv\n",
    "from pandas import *\n",
    "import pandas as pd\n",
    "fp = DataFrame(read_csv(\"gaze.csv\"))\n",
    "data = fp[\"gaze_timestamp\"]\n",
    "#tlst = map(time.localtime, csv_data['gaze_timestamp'])\n",
    "pd.set_option('mode.chained_assignment', None)\n",
    "data_1 = data.copy()\n",
    "for i in range(len(data)):\n",
    "    data_1[i] = str(datetime.fromtimestamp(data[i])).replace('.', '+')\n",
    "print(data_1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5fff8b2",
   "metadata": {},
   "source": [
    "## 第四题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "35117257",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在08:29:12，采样率为426HZ\n",
      "在08:33:45，采样率为427HZ\n",
      "在08:34:01，采样率为425HZ\n"
     ]
    }
   ],
   "source": [
    "test = ['08:29:12','08:33:45','08:34:01']\n",
    "for i in test:\n",
    "    s = list(filter(lambda x: i in x,data_1))\n",
    "    print('在{}，采样率为{}HZ'.format(i,len(s)))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c6979a81",
   "metadata": {},
   "source": [
    "## 第五题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "69d53e81",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    gaze_timestamp  world_index  confidence  norm_pos_x  norm_pos_y  \\\n",
      "0      88150.77678          0.0    0.828006    0.531433    0.397509   \n",
      "4      88150.78749          1.0    0.502595    0.340109    0.142989   \n",
      "7      88150.79358          1.0    0.625134    0.495993    0.399021   \n",
      "10     88150.80114          1.0    0.708476    0.495145    0.408338   \n",
      "15     88150.81287          2.0    0.856341    0.494809    0.402125   \n",
      "19     88150.82182          2.0    0.861113    0.493453    0.399839   \n",
      "24     88150.83164          2.0    0.792455    0.493563    0.398007   \n",
      "28     88150.84223          2.0    0.861801    0.492774    0.399444   \n",
      "32     88150.85154          3.0    0.814635    0.492873    0.398930   \n",
      "37     88150.86204          3.0    0.865288    0.492819    0.397986   \n",
      "41     88150.87173          3.0    0.779778    0.492253    0.398470   \n",
      "45     88150.88174          4.0    0.945000    0.492318    0.398976   \n",
      "49     88150.89000          4.0    0.825607    0.492182    0.397400   \n",
      "54     88150.90154          4.0    0.821103    0.491613    0.397495   \n",
      "58     88150.91139          5.0    0.929133    0.491363    0.398149   \n",
      "63     88150.92348          5.0    0.856588    0.491535    0.396166   \n",
      "66     88150.93188          5.0    0.998202    0.491173    0.396201   \n",
      "70     88150.94089          5.0    0.739421    0.491423    0.397075   \n",
      "75     88150.95150          6.0    0.803616    0.491446    0.396408   \n",
      "79     88150.96149          6.0    0.839119    0.490797    0.397549   \n",
      "\n",
      "                                  base_data  gaze_point_3d_x  gaze_point_3d_y  \\\n",
      "0                             88150.77678-0        28.369753        52.033135   \n",
      "4                            88150.787485-1      -139.404860       175.088321   \n",
      "7         88150.79569-0 88150.79147699999-1         1.533100       -21.730862   \n",
      "10            88150.801157-0 88150.801123-1         1.782444       -18.930993   \n",
      "15            88150.809749-0 88150.815997-1         1.914321       -20.302480   \n",
      "19            88150.823534-0 88150.820104-1         2.451823       -21.099370   \n",
      "24       88150.831679-0 88150.83159799999-1         2.429748       -21.654815   \n",
      "28       88150.841019-0 88150.84344899999-1         2.740186       -21.448818   \n",
      "32       88150.85153599999-0 88150.851534-1         2.713785       -21.649325   \n",
      "37       88150.864506-0 88150.85956499999-1         2.747912       -21.958249   \n",
      "41       88150.87172699999-0 88150.871726-1         2.969824       -21.893036   \n",
      "45             88150.879586-0 88150.88389-1         2.944876       -21.783872   \n",
      "49            88150.888291-0 88150.891702-1         3.013483       -22.246902   \n",
      "54  88150.89951199999-0 88150.90357499999-1         3.240232       -22.277270   \n",
      "58  88150.91139099999-0 88150.91137999999-1         3.339173       -22.149845   \n",
      "63  88150.91942399999-0 88150.92752699999-1         3.288905       -22.693312   \n",
      "66  88150.93622799999-0 88150.92752699999-1         3.440890       -22.760252   \n",
      "70       88150.940894-0 88150.94089099999-1         3.334885       -22.510936   \n",
      "75       88150.947523-0 88150.95548399999-1         3.321167       -22.624493   \n",
      "79       88150.963521-0 88150.95945699999-1         3.571551       -22.364811   \n",
      "\n",
      "    gaze_point_3d_z  eye_center0_3d_x  ...  eye_center0_3d_z  gaze_normal0_x  \\\n",
      "0        705.121116         20.000000  ...        -20.000000        0.011527   \n",
      "4        681.151453        -39.934928  ...        -20.075283       -0.136989   \n",
      "7       -298.890441         20.000000  ...        -20.000000        0.065145   \n",
      "10      -286.849309         20.000000  ...        -20.000000        0.067222   \n",
      "15      -288.102445         20.000000  ...        -20.000000        0.066338   \n",
      "19      -292.574406         20.000000  ...        -20.000000        0.063320   \n",
      "24      -294.883347         20.000000  ...        -20.000000        0.062870   \n",
      "28      -296.254320         20.000000  ...        -20.000000        0.061462   \n",
      "32      -297.501283         20.000000  ...        -20.000000        0.061283   \n",
      "37      -298.954997         20.000000  ...        -20.000000        0.060837   \n",
      "41      -299.487170         20.000000  ...        -20.000000        0.059950   \n",
      "45      -299.486159         20.000000  ...        -20.000000        0.060040   \n",
      "49      -301.155509         20.000000  ...        -20.000000        0.059439   \n",
      "54      -301.844558         20.000000  ...        -20.000000        0.058504   \n",
      "58      -302.044727         20.000000  ...        -20.000000        0.058121   \n",
      "63      -303.545591         20.000000  ...        -20.000000        0.057982   \n",
      "66      -304.543969         20.000000  ...        -20.000000        0.057256   \n",
      "70      -303.767708         20.000000  ...        -20.000000        0.057780   \n",
      "75      -303.334427         20.000000  ...        -20.000000        0.057914   \n",
      "79      -303.192161         20.000000  ...        -20.000000        0.057075   \n",
      "\n",
      "    gaze_normal0_y  gaze_normal0_z  eye_center1_3d_x  eye_center1_3d_y  \\\n",
      "0         0.051002        0.998632               NaN               NaN   \n",
      "4         0.220475        0.965725               NaN               NaN   \n",
      "7         0.027374        0.997500        -39.934928         14.997919   \n",
      "10        0.026625        0.997383        -39.934928         14.997919   \n",
      "15        0.023840        0.997512        -39.934928         14.997919   \n",
      "19        0.025199        0.997675        -39.934928         14.997919   \n",
      "24        0.027411        0.997645        -39.934928         14.997919   \n",
      "28        0.024975        0.997797        -39.934928         14.997919   \n",
      "32        0.025669        0.997790        -39.934928         14.997919   \n",
      "37        0.025458        0.997823        -39.934928         14.997919   \n",
      "41        0.025325        0.997880        -39.934928         14.997919   \n",
      "45        0.024936        0.997884        -39.934928         14.997919   \n",
      "49        0.025782        0.997899        -39.934928         14.997919   \n",
      "54        0.025053        0.997973        -39.934928         14.997919   \n",
      "58        0.024277        0.998014        -39.934928         14.997919   \n",
      "63        0.026013        0.997979        -39.934928         14.997919   \n",
      "66        0.025568        0.998032        -39.934928         14.997919   \n",
      "70        0.024715        0.998023        -39.934928         14.997919   \n",
      "75        0.025849        0.997987        -39.934928         14.997919   \n",
      "79        0.023795        0.998086        -39.934928         14.997919   \n",
      "\n",
      "    eye_center1_3d_z  gaze_normal1_x  gaze_normal1_y  gaze_normal1_z  \n",
      "0                NaN             NaN             NaN             NaN  \n",
      "4                NaN             NaN             NaN             NaN  \n",
      "7         -20.075283       -0.145087        0.230744        0.962137  \n",
      "10        -20.075283       -0.152523        0.222659        0.962891  \n",
      "15        -20.075283       -0.152094        0.233980        0.960271  \n",
      "19        -20.075283       -0.151527        0.234143        0.960321  \n",
      "24        -20.075283       -0.150210        0.233747        0.960624  \n",
      "28        -20.075283       -0.150562        0.233448        0.960642  \n",
      "32        -20.075283       -0.149817        0.233036        0.960859  \n",
      "37        -20.075283       -0.149152        0.234053        0.960715  \n",
      "41        -20.075283       -0.149645        0.233258        0.960831  \n",
      "45        -20.075283       -0.149568        0.232896        0.960931  \n",
      "49        -20.075283       -0.148916        0.233733        0.960829  \n",
      "54        -20.075283       -0.149322        0.234031        0.960694  \n",
      "58        -20.075283       -0.149559        0.233748        0.960726  \n",
      "63        -20.075283       -0.148602        0.234394        0.960717  \n",
      "66        -20.075283       -0.148602        0.234394        0.960717  \n",
      "70        -20.075283       -0.148648        0.234240        0.960747  \n",
      "75        -20.075283       -0.148821        0.234277        0.960712  \n",
      "79        -20.075283       -0.149733        0.234649        0.960479  \n",
      "\n",
      "[20 rows x 21 columns]\n"
     ]
    }
   ],
   "source": [
    "record = 'x'\n",
    "\n",
    "count = 0\n",
    "collection = []\n",
    "for i in range(len(data_1)):\n",
    "    if count == 20:\n",
    "        break\n",
    "    if data_1[i][21] != record:\n",
    "        count+=1\n",
    "        record = data_1[i][21]\n",
    "        collection.append(i)\n",
    "data_2 = pd.DataFrame()\n",
    "for j in collection:\n",
    "    data_2=data_2.append(fp.loc[j])\n",
    "print(data_2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8766236e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
